<?php namespace Framework\Kernel;

require 'Framework/Org/Smarty/Smarty.class.php';

//基础控制器
class Controller extends \Smarty
{
	public $template_dir;
	public $compile_dir;
	public $left_delimiter='{{';
	public $right_delimiter='}}';

	public function __construct()
	{
		$this->template_dir = 'app/'.MODULE.'/View/'.CONTROLLER;
		$this->compile_dir = 'storage/view/'.MODULE;

		if(!is_dir($this->compile_dir))
		{
			mkdir($this->compile_dir,0755,true);
		}
		//如果继承类中存在__init方法时，执行
		if(method_exists($this, '__init'))
		{
			$this->__init();
		}
	}

	//成功的方法
	public function success($message,$url='')
	{
		$url = $url?$url:$_SERVER['HTTP_REFERER'];
		$this->assign('url',$url);
		$this->assign('message',$message);
		$this->template_dir='public';
		$this->display('success.php');
	}

	//成功的方法
	public function error($message,$url='')
	{
		$url = $url?$url:$_SERVER['HTTP_REFERER'];
		$this->assign('url',$url);
		$this->assign('message',$message);
		$this->template_dir='public';
		$this->display('error.php');
	}

	//ajax 返回数据
	public function ajax($data)
	{
		echo json_encode($data);
		exit;
	}
}












